home *** CD-ROM | disk | FTP | other *** search
- // ==================================================
- // CTouchMeAppleEvents.cp
- // a part of CTouchMeApp.cp
- // Copyright (C) 1996 Mizutori Tetsuya, July 4 1996.
- // ==================================================
- // All documents are pretty-printed in Geneva 10-point font.
-
-
- #include <UAppleEventsMgr.h>
- #include <UExtractFromAEDesc.h>
-
-
- #include "touchMeConstants.h"
- #include "CTouchMeAppleEvents.h"
- #include "CTouchMeApp.h"
- #include "CTouchMePref.h"
- #include "CTouchMeDialog.h"
- #include "UFileInfo.h"
-
- extern CTouchMePref * gPref;
- extern CTouchMeDialog * gDialog;
-
- #define longDateTimeHi( a ) (((LongDateCvt *) &(a))->hl.lHigh)
- #define longDateTimeLo( a ) (((LongDateCvt *) &(a))->hl.lLow)
-
-
- // Making a 'TheLongDateTime()' function from a template.
- // See also examples in the source code 'UExtractFromAEDesc.cp'.
-
- #ifdef COMMENT
- static void
- CTouchMeApp::TheLongDateTime(
- const AEDesc &inDesc,
- LongDateTime &outValue );
- #endif // COMMENT
-
- // --------------------------------------------------
- #undef Extractor_Name
- #undef C_DataType
- #undef AE_DataType
-
- #define Extractor_Name TheLongDateTime
- #define C_DataType LongDateTime
- #define AE_DataType typeLongDateTime
-
- #undef UExtractFromAEDesc
- #define UExtractFromAEDesc CTouchMeApp
- #include <AEDescExtractor.t>
- #undef UExtractFromAEDesc
- // --------------------------------------------------
-
-
-
- // --------------------------------------------------
- // ・ HandleAppleEvent
- // --------------------------------------------------
- // Respond to an AppleEvent
-
- void
- CTouchMeApp::HandleAppleEvent(
- const AppleEvent & inAppleEvent,
- AppleEvent & outAEReply,
- AEDesc & outResult,
- long inAENumber )
- {
-
- switch ( inAENumber ) {
- case ae_GetPrefs:
- HandleGetPrefs( inAppleEvent, outAEReply, outResult );
- break;
-
- case ae_SetPrefs:
- HandleSetPrefs( inAppleEvent, outAEReply, outResult );
- break;
-
- case ae_LoadPrefs:
- HandleLoadPrefs( inAppleEvent, outAEReply, outResult );
- break;
-
- case ae_SavePrefs:
- HandleSavePrefs( inAppleEvent, outAEReply, outResult );
- break;
-
- case ae_Touch:
- HandleTouch( inAppleEvent, outAEReply, outResult );
- break;
-
- case ae_Fetch:
- HandleFetch( inAppleEvent, outAEReply, outResult );
- break;
-
- default:
- LDocApplication::HandleAppleEvent(
- inAppleEvent, outAEReply, outResult, inAENumber );
- break;
- }
- }
-
-
- // --------------------------------------------------
- // ・ HandleGetPrefs
- // --------------------------------------------------
-
- void
- CTouchMeApp::HandleGetPrefs(
- const AppleEvent &inAppleEvent,
- AppleEvent &outAEReply,
- AEDesc &outResult )
- {
- ETouchType theTouchType; // 'creation' or 'modification' type
- OSErr err;
-
- // Get the 1st required parameter as 'typeEnumerated'.
- StAEDescriptor theRequiredDesc;
- theRequiredDesc.GetParamDesc( inAppleEvent, keyDirectObject, typeEnumerated );
- OSType theEnumValue;
- UExtractFromAEDesc::TheEnum( theRequiredDesc.mDesc, theEnumValue );
- switch ( theEnumValue ) {
- case kEnumType_Creation:
- theTouchType = touchType_CreationDate;
- break;
- case kEnumType_Modification:
- theTouchType = touchType_ModificationDate;
- break;
- default:
- ThrowIfOSErr_( errAEWrongDataType ); // Error.
- break;
- }
-
- // Error if there are more parameters.
- UAppleEventsMgr::CheckForMissedParams( inAppleEvent );
-
-
- // Dispose the original descriptor given by the system.
- // Instead, create my own descriptor, a record type with true option, otherwise a list type.
- ::AEDisposeDesc( &outResult );
- outResult.dataHandle = nil;
- //err = ::AECreateDesc(typeLongInteger, &theSize, sizeof(Int32), &outResult);
- err = ::AECreateList( nil, 0, true, &outResult );
- ThrowIfOSErr_( err );
-
-
- // If dialog window is open, then read the settings from the dialog.
- if ( gDialog != nil ) gDialog->InspectDialog( *gPref );
-
- // Return the gPref data as an AppleEvent record.
- // 1. Enabled
- Boolean theEnabled = gPref->GetEnabled( theTouchType );
-
- // 2. Flag
- OSType theFlag;
- switch ( gPref->GetFlagNumb( theTouchType ) ) {
- case touchFlag_Current:
- theFlag = kEnumFlag_Current; break;
- case touchFlag_Direct:
- theFlag = kEnumFlag_Excact; break;
- case touchFlag_First:
- theFlag = kEnumFlag_First; break;
- case touchFlag_Second:
- theFlag = kEnumFlag_FirstSet; break;
- default:
- theFlag = typeNull; break;
- }
-
- // 3. Value
- LongDateTime theDateTimeSecs;
- longDateTimeHi( theDateTimeSecs ) = 0;
- longDateTimeLo( theDateTimeSecs ) = gPref->GetDateTime( theTouchType );
-
- // Prepare to create members of descriptor record.
- StAEDescriptor theDescEnabled( (Boolean) theEnabled );
- StAEDescriptor theDescFlag( typeEnumerated, &theFlag, sizeof(OSType) );
- StAEDescriptor theDescDate( typeLongDateTime, &theDateTimeSecs, sizeof(LongDateTime) );
-
- // Insert the members into to the descriptor record.
- UAEDesc::AddKeyDesc( &outResult, pPref_Enabled, theDescEnabled.mDesc );
- UAEDesc::AddKeyDesc( &outResult, pPref_Flag, theDescFlag.mDesc );
- UAEDesc::AddKeyDesc( &outResult, pPref_Value, theDescDate.mDesc );
- }
-
-
- // --------------------------------------------------
- // ・ HandleSetPrefs
- // --------------------------------------------------
-
- void
- CTouchMeApp::HandleSetPrefs(
- const AppleEvent &inAppleEvent,
- AppleEvent &outAEReply,
- AEDesc &outResult )
- {
- ETouchType theTouchType; // 'creation' or 'modification'
- OSErr err;
-
- // Get the 1st required parameter as 'typeEnumerated'.
- StAEDescriptor theRequiredDesc;
- theRequiredDesc.GetParamDesc( inAppleEvent, keyDirectObject, typeEnumerated );
- OSType theEnumValue;
- UExtractFromAEDesc::TheEnum( theRequiredDesc.mDesc, theEnumValue );
- switch ( theEnumValue ) {
- case kEnumType_Creation:
- theTouchType = touchType_CreationDate;
- break;
- case kEnumType_Modification:
- theTouchType = touchType_ModificationDate;
- break;
- default:
- ThrowIfOSErr_( errAEWrongDataType ); // Error.
- break;
- }
-
- // Get the 2nd required parameter as 'typeAERecord'.
- StAEDescriptor theDescData;
- theDescData.GetParamDesc( inAppleEvent, keyAEData, typeAERecord );
- //theDescData.GetParamDesc( inAppleEvent, keyAEData, typeWildCard );
-
- // Error if there are more parameters.
- UAppleEventsMgr::CheckForMissedParams( inAppleEvent );
-
-
- // Prepare to create members of descriptor record.
- StAEDescriptor theDescEnabled;
- StAEDescriptor theDescFlag;
- StAEDescriptor theDescDate;
-
- // Get descriptors from the descriptor record.
- theDescEnabled.GetOptionalParamDesc( theDescData.mDesc, pPref_Enabled, typeBoolean );
- theDescFlag.GetOptionalParamDesc( theDescData.mDesc, pPref_Flag, typeEnumerated );
- theDescDate.GetOptionalParamDesc( theDescData.mDesc, pPref_Value, typeLongDateTime );
-
- // Read the gPref data from an AppleEvent descriptor.
- // 1. Enabled
- Boolean theEnabled = gPref->GetEnabled( theTouchType );
- if ( theDescEnabled.mDesc.descriptorType != typeNull )
- UExtractFromAEDesc::TheBoolean( theDescEnabled.mDesc, theEnabled );
- gPref->SetEnabled( theTouchType, theEnabled );
-
- // 2. Flag
- ETouchFlag theFlag = gPref->GetFlagNumb( theTouchType );
- OSType theAEFlag = typeNull;
- if ( theDescFlag.mDesc.descriptorType != typeNull )
- UExtractFromAEDesc::TheEnum( theDescFlag.mDesc, theAEFlag );
- switch ( theAEFlag ) {
- case kEnumFlag_Current: theFlag = touchFlag_Current; break;
- case kEnumFlag_Excact: theFlag = touchFlag_Direct; break;
- case kEnumFlag_First: theFlag = touchFlag_First; break;
- case kEnumFlag_FirstSet: theFlag = touchFlag_Second; break;
- default: break;
- }
- gPref->SetFlagNumb( theTouchType, theFlag );
-
- // 3. Value
- LongDateTime theDateTimeSecs;
- longDateTimeHi( theDateTimeSecs ) = 0;
- longDateTimeLo( theDateTimeSecs ) = gPref->GetDateTime( theTouchType );
- if ( theDescDate.mDesc.descriptorType != typeNull )
- CTouchMeApp::TheLongDateTime( theDescDate.mDesc, theDateTimeSecs );
- gPref->SetDateTime( theTouchType, longDateTimeLo( theDateTimeSecs ) );
-
- // If dialog window is open, then setup the dialog according to the preferences.
- if ( gDialog != nil ) gDialog->SetupDialog( *gPref );
- }
-
-
- // --------------------------------------------------
- // ・ HandleLoadPrefs
- // --------------------------------------------------
-
- void
- CTouchMeApp::HandleLoadPrefs(
- const AppleEvent &inAppleEvent,
- AppleEvent &outAEReply,
- AEDesc &outResult )
- {
- gPref->LoadPrefData();
-
- // If dialog window is open, then setup the dialog according to the preferences.
- if ( gDialog != nil ) gDialog->SetupDialog( *gPref );
- }
-
-
- // --------------------------------------------------
- // ・ HandleSavePrefs
- // --------------------------------------------------
-
- void
- CTouchMeApp::HandleSavePrefs(
- const AppleEvent &inAppleEvent,
- AppleEvent &outAEReply,
- AEDesc &outResult )
- {
- // If dialog window is open, then read the settings from the dialog.
- if ( gDialog != nil ) gDialog->InspectDialog( *gPref );
-
- gPref->SavePrefData();
- }
-
-
- // --------------------------------------------------
- // ・ HandleTouch
- // --------------------------------------------------
-
- void
- CTouchMeApp::HandleTouch(
- const AppleEvent &inAppleEvent,
- AppleEvent &outAEReply,
- AEDesc &outResult )
- {
- OSErr err;
-
- // Get the 1st required parameter as 'typeAEList'.
- StAEDescriptor theDocListDesc;
- theDocListDesc.GetParamDesc( inAppleEvent, keyDirectObject, typeAEList );
-
- long theCount;
- err = ::AECountItems( &(theDocListDesc.mDesc), &theCount );
- ThrowIfOSErr_( err );
-
- for ( long index = 1; index <= theCount; index++ ) {
- AEKeyword theKey;
- DescType theType;
- FSSpec theFileSpec;
- Size theSize;
- err = ::AEGetNthPtr( &(theDocListDesc.mDesc), index, typeFSS,
- &theKey, &theType, (Ptr) &theFileSpec, sizeof(FSSpec), &theSize );
- ThrowIfOSErr_( err );
-
- OpenDocument( &theFileSpec );
- }
- }
-
-
- // --------------------------------------------------
- // ・ HandleFetch
- // --------------------------------------------------
-
- void
- CTouchMeApp::HandleFetch(
- const AppleEvent &inAppleEvent,
- AppleEvent &outAEReply,
- AEDesc &outResult )
- {
- OSErr err;
-
- unsigned long theCreationDate, theModificationDate;
- ::GetDateTime( &theCreationDate );
- ::GetDateTime( &theModificationDate );
-
- // Get the 1st required parameter as 'typeAEList'.
- StAEDescriptor theDocListDesc;
- theDocListDesc.GetParamDesc( inAppleEvent, keyDirectObject, typeAEList );
-
- long theCount;
- err = ::AECountItems( &(theDocListDesc.mDesc), &theCount );
- ThrowIfOSErr_( err );
-
- for ( long index = 1; index <= theCount; index++ ) {
- AEKeyword theKey;
- DescType theType;
- FSSpec theFileSpec;
- Size theSize;
- err = ::AEGetNthPtr( &(theDocListDesc.mDesc), index, typeFSS,
- &theKey, &theType, (Ptr) &theFileSpec, sizeof(FSSpec), &theSize );
- ThrowIfOSErr_( err );
-
- UFileInfo::GetFSSpecDateTime( theFileSpec, theCreationDate, theModificationDate );
- }
-
- gPref->SetDateTime( touchType_CreationDate, theCreationDate );
- gPref->SetDateTime( touchType_ModificationDate, theModificationDate );
-
- // If dialog window is open, then setup the dialog according to the preferences.
- if ( gDialog != nil ) gDialog->SetupDialog( *gPref );
-
- // Dispose the original descriptor given by the System.
- // Instead, create my own descriptor, a record type with true option, otherwise a list type.
- ::AEDisposeDesc( &outResult );
- outResult.dataHandle = nil;
- //err = ::AECreateDesc(typeLongInteger, &theSize, sizeof(Int32), &outResult);
- err = ::AECreateList( nil, 0, true, &outResult );
- ThrowIfOSErr_( err );
-
- LongDateTime theCrDateTimeSecs, theMdDateTimeSecs;
- longDateTimeHi( theCrDateTimeSecs ) = 0;
- longDateTimeLo( theCrDateTimeSecs ) = theCreationDate;
- longDateTimeHi( theMdDateTimeSecs ) = 0;
- longDateTimeLo( theMdDateTimeSecs ) = theModificationDate;
-
- // Prepare to create members of descriptor record.
- StAEDescriptor theCrDateDesc( typeLongDateTime, &theCrDateTimeSecs, sizeof(LongDateTime) );
- StAEDescriptor theMdDateDesc( typeLongDateTime, &theMdDateTimeSecs, sizeof(LongDateTime) );
-
- // Insert the members into to the descriptor record.
- UAEDesc::AddKeyDesc( &outResult, pStamp_Creation, theCrDateDesc.mDesc );
- UAEDesc::AddKeyDesc( &outResult, pStamp_Modification, theMdDateDesc.mDesc );
- }
-
-
- // end of program
-